package com.happyscan138.makefun;

import android.app.Activity;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.Toast;

import com.happyscan138.makefun.Urls.Urls;
import com.happyscan138.makefun.base.VideoPlayView;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.JsonHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.squareup.picasso.Picasso;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

import cz.msebera.android.httpclient.Header;
import pl.droidsonroids.gif.GifDrawable;
import pl.droidsonroids.gif.GifImageView;

import static com.happyscan138.makefun.base.Uri.getPhotoPathFromContentUri;
import static com.happyscan138.makefun.base.bitmap.getSmallBitmap;
import static com.happyscan138.makefun.base.bitmap.saveMyBitmap;
import static com.happyscan138.makefun.base.http.client;
import static com.happyscan138.makefun.base.http.params;
import static com.loopj.android.http.AsyncHttpClient.log;

/**
 * Created by Administrator on 2016/12/17.
 */

public class creatQuestion extends AppCompatActivity implements View.OnClickListener, VideoPlayView.MediaPlayerImpl {
    private Button Release;
    private LinearLayout linearLayoutA,linearLayoutB,linearLayoutC,linearLayoutD;
    private EditText editTextsubject,editTextAnswerA,editTextAnswerB,editTextAnswerC,editTextAnswerD;
    private ImageView imageView,imageViewA,imageViewB,imageViewC,imageViewD;
    private ImageButton Back,input_image,input_voice;
    private ImageButton Answer_Input_Image_A,Answer_Input_Video_A,Answer_Input_Voice_A,
            Answer_Input_Image_B,Answer_Input_Video_B,Answer_Input_Voice_B,
            Answer_Input_Image_C,Answer_Input_Video_C,Answer_Input_Voice_C,
            Answer_Input_Image_D,Answer_Input_Video_D,Answer_Input_Voice_D;
    private String Subject,answerA,answerB,answerC,answerD;
    private SharedPreferences preferences;
    private SharedPreferences.Editor editor;
    private String access_key;
    private String QuestionPath,imagePathA,imagePathB,imagePathC,imagePathD;
    private Intent intent;
    private File fileImg,fileImgA,fileImgB,fileImgC,fileImgD;
    private int spoof_typeA,spoof_typeB,spoof_typeC,spoof_typeD;
    private Uri uri,uriA,uriB,uriC,uriD;
    private  String contentA,contentB,contentC,contentD;
    private  String SpoofImaA,SpoofImaB,SpoofImaC,SpoofImaD;
    private File fileSpoofFileA,fileSpoofFileB,fileSpoofFileC,fileSpoofFileD;
    private int type_id;
    private LayoutInflater inflater;
    private MediaPlayer mediaPlayer;
    private int AnswerTypeIdA,AnswerTypeIdB,AnswerTypeIdC,AnswerTypeIdD;
    private ImageButton Saoku,SaokuA,SaokuB,SaokuC,SaokuD;
    private ImageButton special_A,special_B,special_C,special_D;
    private String textSpecialA,textSpecialB,textSpecialC,textSpecialD;
    private PopupWindow pop;
    private boolean isPlaying;
    private static final long MAX_POST_SIZE = 4 * 1024 * 1024;
    private String SaokuResource,SaokuResourceA,SaokuResourceB,SaokuResourceC,SaokuResourceD;
    private Bitmap bitmapQuestion;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.creat_question);
        client=new AsyncHttpClient();
        params=new RequestParams();
        preferences = getSharedPreferences("UserInfo", MODE_PRIVATE);
        access_key = preferences.getString("UserId","");
        Log.e("access_key_main",access_key);
        initView();
    }

    public void initView(){
        inflater = LayoutInflater.from(this);
        TextChange textChange=new TextChange();
        linearLayoutA=(LinearLayout)findViewById(R.id.special_answerA);
        linearLayoutB=(LinearLayout)findViewById(R.id.special_answerB);
        linearLayoutC=(LinearLayout)findViewById(R.id.special_answerC);
        linearLayoutD=(LinearLayout)findViewById(R.id.special_answerD);
        Back=(ImageButton)findViewById(R.id.creatQuestion_Back);
        Back.setOnClickListener(this);
        Release=(Button)findViewById(R.id.creatQuestion_release);
        Release.setOnClickListener(this);
        editTextsubject=(EditText)findViewById(R.id.input_question);
        editTextsubject.addTextChangedListener(textChange);
        imageView=(ImageView)findViewById(R.id.creatQuestion_image);
        imageView.setOnClickListener(this);
        imageViewA=(ImageView)findViewById(R.id.creatQuestion_AnswerA_Image);
        imageViewB=(ImageView)findViewById(R.id.creatQuestion_AnswerB_Image) ;
        imageViewC=(ImageView)findViewById(R.id.creatQuestion_AnswerC_Image) ;
        imageViewD=(ImageView)findViewById(R.id.creatQuestion_AnswerD_Image) ;
        input_image=(ImageButton)findViewById(R.id.creatQuestion_Input_image);
        input_image.setOnClickListener(this);
        Answer_Input_Image_A=(ImageButton)findViewById(R.id.Answer_A_image);
        Answer_Input_Image_A.setOnClickListener(this);
        Answer_Input_Image_B=(ImageButton)findViewById(R.id.Answer_B_Image);
        Answer_Input_Image_B.setOnClickListener(this);
        Answer_Input_Image_C=(ImageButton)findViewById(R.id.Answer_C_Image);
        Answer_Input_Image_C.setOnClickListener(this);
        Answer_Input_Image_D=(ImageButton)findViewById(R.id.Answer_D_Image);
        Answer_Input_Image_D.setOnClickListener(this);
        Answer_Input_Video_A=(ImageButton)findViewById(R.id.Answer_A_Video);
        Answer_Input_Video_A.setOnClickListener(this);
        Answer_Input_Video_B=(ImageButton)findViewById(R.id.Answer_B_Video);
        Answer_Input_Video_B.setOnClickListener(this);
        Answer_Input_Video_C=(ImageButton)findViewById(R.id.Answer_C_Video);
        Answer_Input_Video_C.setOnClickListener(this);
        Answer_Input_Video_D=(ImageButton)findViewById(R.id.Answer_D_Video);
        Answer_Input_Video_D.setOnClickListener(this);
        editTextAnswerA=(EditText)findViewById(R.id.creatQuestion_AnswerA);
        editTextAnswerA.addTextChangedListener(textChange);
        editTextAnswerB=(EditText)findViewById(R.id.creatQuestion_AnswerB);
        editTextAnswerB.addTextChangedListener(textChange);
        editTextAnswerC=(EditText)findViewById(R.id.creatQuestion_AnswerC);
        editTextAnswerC.addTextChangedListener(textChange);
        editTextAnswerD=(EditText)findViewById(R.id.creatQuestion_AnswerD);
        editTextAnswerD.addTextChangedListener(textChange);
        input_voice=(ImageButton)findViewById(R.id.creatQuestion_Input_Voice);
        input_voice.setOnClickListener(this);
        Answer_Input_Voice_A=(ImageButton)findViewById(R.id.Answer_A_Voice);
        Answer_Input_Voice_A.setOnClickListener(this);
        Answer_Input_Voice_B=(ImageButton)findViewById(R.id.Answer_B_Voice);
        Answer_Input_Voice_B.setOnClickListener(this);
        Answer_Input_Voice_C=(ImageButton)findViewById(R.id.Answer_C_Voice);
        Answer_Input_Voice_C.setOnClickListener(this);
        Answer_Input_Voice_D=(ImageButton)findViewById(R.id.Answer_D_Voice);
        Answer_Input_Voice_D.setOnClickListener(this);
        Saoku=(ImageButton)findViewById(R.id.creatQuestion_Input_Release);
        Saoku.setOnClickListener(this);
        SaokuA=(ImageButton)findViewById(R.id.Answer_A_Release);
        SaokuA.setOnClickListener(this);
        SaokuB=(ImageButton)findViewById(R.id.Answer_B_Release);
        SaokuB.setOnClickListener(this);
        SaokuC=(ImageButton)findViewById(R.id.Answer_C_Release);
        SaokuC.setOnClickListener(this);
        SaokuD=(ImageButton)findViewById(R.id.Answer_D_Release);
        SaokuD.setOnClickListener(this);
        linearLayoutA.setOnClickListener(this);
        linearLayoutB.setOnClickListener(this);
        linearLayoutC.setOnClickListener(this);
        linearLayoutD.setOnClickListener(this);
        special_A=(ImageButton)findViewById(R.id.Answer_A_Special);
        special_A.setOnClickListener(this);
        special_B=(ImageButton)findViewById(R.id.Answer_B_Special);
        special_B.setOnClickListener(this);
        special_C=(ImageButton)findViewById(R.id.Answer_C_Special);
        special_C.setOnClickListener(this);
        special_D=(ImageButton)findViewById(R.id.Answer_D_Special);
        special_D.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {

        switch (v.getId()){
            case R.id.Answer_A_Special:
                intent=new Intent();
                intent.setClass(creatQuestion.this,setSpecial.class);
                startActivityForResult(intent,040);
                break;
            case R.id.Answer_B_Special:
                intent=new Intent();
                intent.setClass(creatQuestion.this,setSpecial.class);
                startActivityForResult(intent,041);
                break;
            case R.id.Answer_C_Special:
                intent=new Intent();
                intent.setClass(creatQuestion.this,setSpecial.class);
                startActivityForResult(intent,042);
                break;
            case R.id.Answer_D_Special:
                intent=new Intent();
                intent.setClass(creatQuestion.this,setSpecial.class);
                startActivityForResult(intent,043);
                break;

            case R.id.creatQuestion_Back:
                finish();
                break;
            case R.id.creatQuestion_release:
                if(params.equals(null)){
                    Toast.makeText(this,"请输入内容",Toast.LENGTH_LONG).show();
                    log.e("imagePathA",params.toString());
                }else {
                    //判断路径格式，设置type_id并转换成file
                    if (imagePathA == null && SaokuResourceA == null) {
                        AnswerTypeIdA = 1;
                    } else if (imagePathA != null && SaokuResourceA == null) {
                        if (imagePathA.endsWith(".jpg") || imagePathA.endsWith(".png")) {
                            fileImgA = saveMyBitmap(getSmallBitmap(imagePathA), imagePathA);

                            AnswerTypeIdA = 2;
                            log.e("type_idcreat", AnswerTypeIdA + "");
                        } else if (imagePathA.endsWith(".mp4")) {
                            AnswerTypeIdA = 3;
                            fileImgA = new File(imagePathA);
                        } else if (imagePathA.endsWith(".mp3")) {
                            AnswerTypeIdA = 4;
                        }
                        fileImgA = new File(imagePathA);
                        long length = fileImgA.length();
                        log.e("length", length + "");
                        if (length > MAX_POST_SIZE) {
                            Toast.makeText(this, "答案A上传文件大于4M", Toast.LENGTH_SHORT).show();
                        }
                    } else if (SaokuResource != null && imagePathA == null) {
                        if (SaokuResourceA.endsWith(".jpg") || SaokuResourceA.endsWith(".png")) {
                            AnswerTypeIdA = 2;
                        } else if (SaokuResourceA.endsWith(".mp4")) {
                            AnswerTypeIdA = 3;
                        } else if (SaokuResourceA.endsWith(".mp3")) {
                            AnswerTypeIdA = 4;
                        }
                        fileImgA = null;
                    }


                    if (imagePathB == null && SaokuResourceB == null) {
                        AnswerTypeIdB = 1;
                    } else if (imagePathB != null && SaokuResourceB == null) {
                        if (imagePathB.endsWith(".jpg") || imagePathB.endsWith(".png")) {
                            fileImgB = saveMyBitmap(getSmallBitmap(imagePathB), imagePathB);
                            AnswerTypeIdB = 2;
                        } else if (imagePathB.endsWith(".mp4")) {
                            AnswerTypeIdB = 3;
                            fileImgB = new File(imagePathB);
                        } else if (imagePathB.endsWith(".mp3")) {
                            AnswerTypeIdB = 4;
                            fileImgB = new File(imagePathB);
                        }
                        long length = fileImgB.length();
                        if (length > MAX_POST_SIZE) {
                            Toast.makeText(this, "答案B上传文件大于4M", Toast.LENGTH_SHORT).show();
                            log.e("length", length + "");
                        }
                    } else if (SaokuResourceB != null && imagePathB == null) {
                        if (SaokuResourceB.endsWith(".jpg") || SaokuResourceB.endsWith(".png")) {
                            AnswerTypeIdB = 2;
                        } else if (SaokuResourceB.endsWith(".mp4")) {
                            AnswerTypeIdB = 3;
                        } else if (SaokuResourceB.endsWith(".mp3")) {
                            AnswerTypeIdB = 4;
                        }
                        fileImgB = null;
                    }


                    if (imagePathC == null && SaokuResourceC == null) {
                        AnswerTypeIdC = 1;
                    } else if (imagePathC != null && SaokuResourceC == null) {
                        if (imagePathC.endsWith(".jpg") || imagePathC.endsWith(".png")) {
                            fileImgC = saveMyBitmap(getSmallBitmap(imagePathC), imagePathC);
                            AnswerTypeIdC = 2;
                        } else if (imagePathC.endsWith(".mp4")) {
                            AnswerTypeIdC = 3;
                            fileImgC = new File(imagePathC);
                        } else if (imagePathC.endsWith(".mp3")) {
                            AnswerTypeIdC = 4;
                            fileImgC = new File(imagePathC);
                        }
                        long length = fileImgC.length();
                        if (length > MAX_POST_SIZE) {
                            Toast.makeText(this, "答C上传文件大于4M", Toast.LENGTH_SHORT).show();
                            log.e("length", length + "");
                        }
                    } else if (SaokuResourceC != null && imagePathC == null) {
                        if (SaokuResourceC.endsWith(".jpg") || SaokuResourceC.endsWith(".png")) {
                            AnswerTypeIdC = 2;
                        } else if (SaokuResourceC.endsWith(".mp4")) {
                            AnswerTypeIdC = 3;
                        } else if (SaokuResourceC.endsWith(".mp3")) {
                            AnswerTypeIdC = 4;
                        }
                        fileImgC = null;
                    }


                    if (imagePathD == null && SaokuResourceD == null) {
                        AnswerTypeIdD = 1;
                    } else if (imagePathD != null && SaokuResourceD == null) {
                        if (imagePathD.endsWith(".jpg") || imagePathD.endsWith(".png")) {
                            fileImgD = saveMyBitmap(getSmallBitmap(imagePathD), imagePathD);
                            AnswerTypeIdD = 2;
                        } else if (imagePathD.endsWith(".mp4")) {
                            AnswerTypeIdD = 3;
                            fileImgD = new File(imagePathD);
                        } else if (imagePathD.endsWith(".mp3")) {
                            AnswerTypeIdD = 4;
                            fileImgD = new File(imagePathD);
                        }
                        long length = fileImgD.length();
                        if (length > MAX_POST_SIZE) {
                            Toast.makeText(this, "答C上传文件大于4M", Toast.LENGTH_SHORT).show();
                            log.e("length", length + "");
                        }
                    } else if (SaokuResourceD != null && imagePathD == null) {
                        if (SaokuResourceD.endsWith(".jpg") || SaokuResourceD.endsWith(".png")) {
                            AnswerTypeIdD = 2;
                        } else if (SaokuResourceD.endsWith(".mp4")) {
                            AnswerTypeIdD = 3;
                        } else if (SaokuResourceD.endsWith(".mp3")) {
                            AnswerTypeIdD = 4;
                        }
                        fileImgD = null;
                    }


//                    if(QuestionPath!=null) {
//                     if (QuestionPath.endsWith(".jpg") || QuestionPath.endsWith(".png")) {
//                         type_id = 2;
//                         log.e("type_id",type_id+"");
//                         fileImg = saveMyBitmap(getSmallBitmap(QuestionPath), QuestionPath);
//                        } else if (QuestionPath.endsWith(".mp4")) {
//                            type_id = 3;
//                         fileImg=new File(QuestionPath);
//                        } else if (QuestionPath.endsWith(".mp3")) {
//                            type_id = 4;
//                         fileImg=new File(QuestionPath);
//                        }
//                        long length = fileImg.length();
//                        log.e("length", length + "");
//                        if (length > MAX_POST_SIZE) {
//                            Toast.makeText(this, "问题上传文件大于4M", Toast.LENGTH_SHORT).show();
//
//                        }
//                    }else  {
//                        type_id = 1;
//                    }
//
//                    if(SaokuResource!=null&&QuestionPath==null){
//                        if (SaokuResource.endsWith(".jpg") || SaokuResource.endsWith(".png")) {
//                            type_id = 2;
//                        } else if (SaokuResource.endsWith(".mp4")) {
//                            type_id = 3;
//                        } else if (SaokuResource.endsWith(".mp3")) {
//                            type_id = 4;
//                        }
//                        fileImg=null;
//                    }else {
//                        type_id = 1;
//                    }


                    if (QuestionPath == null && SaokuResource == null) {
                        type_id = 1;
                    } else if (QuestionPath != null && SaokuResource == null) {
                        if (QuestionPath.endsWith(".jpg") || QuestionPath.endsWith(".png")) {
                            type_id = 2;
                            log.e("type_id", type_id + "");
                            fileImg = saveMyBitmap(getSmallBitmap(QuestionPath), QuestionPath);
                        } else if (QuestionPath.endsWith(".mp4")) {
                            type_id = 3;
                            fileImg = new File(QuestionPath);
                        } else if (QuestionPath.endsWith(".mp3")) {
                            type_id = 4;
                            fileImg = new File(QuestionPath);
                        }
                        long length = fileImg.length();
                        log.e("length", length + "");
                        if (length > MAX_POST_SIZE) {
                            Toast.makeText(this, "问题上传文件大于4M", Toast.LENGTH_SHORT).show();

                        }
                    } else if (SaokuResource != null && QuestionPath == null) {
                        if (SaokuResource.endsWith(".jpg") || SaokuResource.endsWith(".png")) {
                            type_id = 2;
                        } else if (SaokuResource.endsWith(".mp4")) {
                            type_id = 3;
                        } else if (SaokuResource.endsWith(".mp3")) {
                            type_id = 4;
                        }
                        fileImg = null;
                    }
                    params.put("access_key", access_key);
                    params.put("type_id", type_id);
                    params.put("content", Subject);
                    params.put("saoku_resource", SaokuResource);

                    try {
                        params.put("file", fileImg);
                        params.put("a_file", fileImgA);
                        params.put("b_file", fileImgB);
                        params.put("c_file", fileImgC);
                        params.put("d_file", fileImgD);
                        params.put("a_spoof_file", fileSpoofFileA);
                        params.put("b_spoof_file", fileSpoofFileB);
                        params.put("c_spoof_file", fileSpoofFileC);
                        params.put("d_spoof_file", fileSpoofFileD);
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    }

                    JSONArray jsonArr = new JSONArray();//json格式的数组
                    JSONObject jsonObjArr1 = new JSONObject();
                    JSONObject jsonObjArr2 = new JSONObject();
                    JSONObject jsonObjArr3 = new JSONObject();
                    JSONObject jsonObjArr4 = new JSONObject();

                    try {
                        //给答案设定参数
                        jsonObjArr1.put("flag", "A");
                        jsonObjArr1.put("content", answerA);
                        jsonObjArr1.put("is_real", "0");
                        jsonObjArr1.put("type_id", AnswerTypeIdA);
                        log.e("type_idcreat", AnswerTypeIdA + "");
                        jsonObjArr1.put("spoof_type", spoof_typeA);
                        jsonObjArr1.put("spoof", "惡搞答案");
                        jsonObjArr1.put("answer_saoku_resource", SaokuResourceA);
                        jsonObjArr1.put("sp_type", textSpecialA);

                        jsonObjArr2.put("flag", "B");
                        jsonObjArr2.put("content", answerB);
                        jsonObjArr2.put("is_real", "0");
                        jsonObjArr2.put("type_id", AnswerTypeIdB);
                        jsonObjArr2.put("spoof_type", spoof_typeB);
                        jsonObjArr2.put("spoof", "惡搞答案");
                        jsonObjArr2.put("answer_saoku_resource", SaokuResourceB);
                        jsonObjArr2.put("sp_type", textSpecialB);

                        jsonObjArr3.put("flag", "C");
                        jsonObjArr3.put("content", answerC);
                        jsonObjArr3.put("is_real", "0");
                        jsonObjArr3.put("type_id", AnswerTypeIdC);
                        jsonObjArr3.put("spoof_type", spoof_typeC);
                        jsonObjArr3.put("spoof", "惡搞答案");
                        jsonObjArr3.put("answer_saoku_resource", SaokuResourceC);
                        log.e("SaokuResourceaaaaa", SaokuResourceC);
                        jsonObjArr3.put("sp_type", textSpecialC);

                        jsonObjArr4.put("flag", "D");
                        jsonObjArr4.put("content", answerD);
                        jsonObjArr4.put("is_real", "0");
                        jsonObjArr4.put("type_id", AnswerTypeIdD);
                        jsonObjArr4.put("spoof_type", spoof_typeD);
                        jsonObjArr4.put("spoof", "惡搞答案");
                        jsonObjArr4.put("answer_saoku_resource", SaokuResourceD);
                        log.e("SaokuResourceaaaaaD", SaokuResourceD);
                        jsonObjArr4.put("sp_type", textSpecialD);

                        jsonArr.put(jsonObjArr1);//将json格式的数据放到json格式的数组里
                        jsonArr.put(jsonObjArr2);
                        jsonArr.put(jsonObjArr3);
                        jsonArr.put(jsonObjArr4);

                        params.put("answer_json", jsonArr.toString());
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }

                    Log.e("paramsCreatQuestion", params.toString());

                    //弹出popuwindow
                    LayoutInflater inflater = LayoutInflater.from(this);
                    View view = inflater.inflate(R.layout.waiting, null);
                    pop = new PopupWindow(view, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, false);
                    pop.setOutsideTouchable(false);
                    pop.setFocusable(true);
                    ImageView loadingImg = (ImageView) view.findViewById(R.id.loading_imageView_info);
                    Animation anim = AnimationUtils.loadAnimation(this, R.anim.tip);
                    loadingImg.startAnimation(anim);
                    pop.showAsDropDown(view);
                    client.post(Urls.creat, params, new JsonHttpResponseHandler() {
                        @Override
                        public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                            super.onSuccess(statusCode, headers, response);
                            Log.e("onSuccess", response.toString());
                            String jsonStr = response.toString();
                            try {
                                JSONObject jsonObject = new JSONObject(jsonStr);
                                String msg = jsonObject.getString("msg");
                                pop.dismiss();
                                Toast.makeText(creatQuestion.this, msg, Toast.LENGTH_SHORT).show();
                                startActivity(new Intent(creatQuestion.this, MainActivity.class));

                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                        }

                        @Override
                        public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                            super.onFailure(statusCode, headers, responseString, throwable);
                            Log.e("onSuccess", responseString);
                            pop.dismiss();
                        }
                    });
                }
                break;
                //问题输入图片和视频按钮
            case R.id.creatQuestion_Input_image:
                intent = new Intent();
                intent.setType("video/*;image/*");
                intent.setAction(Intent.ACTION_GET_CONTENT);
                startActivityForResult(intent,  1);
                break;
            case R.id.Answer_A_image:
                intent = new Intent();
                intent.setType("image/*");
                intent.setAction(Intent.ACTION_GET_CONTENT);
                startActivityForResult(intent,  2);
                break;
            case R.id.Answer_B_Image:
                intent = new Intent();
                intent.setType("image/*");
                intent.setAction(Intent.ACTION_GET_CONTENT);
                startActivityForResult(intent,  3);
                break;
            case R.id.Answer_C_Image:
                intent = new Intent();
                intent.setType("image/*");
                intent.setAction(Intent.ACTION_GET_CONTENT);
                startActivityForResult(intent,  4);
                break;
            case R.id.Answer_D_Image:
                intent = new Intent();
                intent.setType("image/*");
                intent.setAction(Intent.ACTION_GET_CONTENT);
                startActivityForResult(intent,  5);
                break;
            case R.id.creatQuestion_Input_Voice:
                intent=new Intent();
                intent.setClass(this,Record.class);
                startActivityForResult(intent,010);
                break;

        /*    点击图片放大
           case R.id.creatQuestion_image:
                LayoutInflater inflater = LayoutInflater.from(this);
                imgEntryView= inflater.inflate(R.layout.larg_image, null); // 加载自定义的布局文件
                final AlertDialog dialog = new AlertDialog.Builder(this).create();
                ImageView img1 = (ImageView)imgEntryView.findViewById(R.id.large_image);
                img1.setImageBitmap(bitmap);
                dialog.setView(imgEntryView); // 自定义dialog
                dialog.show();
                imgEntryView.setOnClickListener(new View.OnClickListener() {
                    public void onClick(View paramView) {
                        dialog.cancel();
                    }
                });
             break; */
            case R.id.special_answerA:
                 intent=new Intent();
                intent.setClass(creatQuestion.this,SpoofAnswer.class);
                startActivityForResult(intent,001);
                break;
            case R.id.special_answerB:
                 intent=new Intent();
                intent.setClass(creatQuestion.this,SpoofAnswer.class);
                startActivityForResult(intent,002);
                break;
            case R.id.special_answerC:
                 intent=new Intent();
                intent.setClass(creatQuestion.this,SpoofAnswer.class);
                startActivityForResult(intent,003);
                break;
            case R.id.special_answerD:
                 intent=new Intent();
                intent.setClass(creatQuestion.this,SpoofAnswer.class);
                startActivityForResult(intent,004);
                break;
            case R.id.Answer_A_Voice:
                intent=new Intent();
                intent.setClass(creatQuestion.this,Record.class);
                startActivityForResult(intent,021);
                break;
            case R.id.Answer_B_Voice:
                intent=new Intent();
                intent.setClass(creatQuestion.this,Record.class);
                startActivityForResult(intent,022);
                break;
            case R.id.Answer_C_Voice:
                intent=new Intent();
                intent.setClass(creatQuestion.this,Record.class);
                startActivityForResult(intent,023);
                break;
            case R.id.Answer_D_Voice:
                intent=new Intent();
                intent.setClass(creatQuestion.this,Record.class);
                startActivityForResult(intent,024);
                break;
            //上传视频
            case R.id.Answer_A_Video:
                intent=new Intent();
                intent.setType("video/*");
                intent.setAction(Intent.ACTION_GET_CONTENT);
                startActivityForResult(intent,030);
                break;
            case R.id.Answer_B_Video:
                Log.e("Answer_B_Video","Answer_B_Video");
                intent=new Intent();
                intent.setType("video/*");
                intent.setAction(Intent.ACTION_GET_CONTENT);
                startActivityForResult(intent,031);
                break;
            case R.id.Answer_C_Video:
                intent=new Intent();
                intent.setType("video/*");
                intent.setAction(Intent.ACTION_GET_CONTENT);
                startActivityForResult(intent,032);
                break;
            case R.id.Answer_D_Video:
                intent=new Intent();
                intent.setType("video/*");
                intent.setAction(Intent.ACTION_GET_CONTENT);
                startActivityForResult(intent,033);
                break;
            case R.id.creatQuestion_Input_Release:
                intent =new Intent();
                intent.setClass(creatQuestion.this,Saoku.class);
                startActivityForResult(intent,050);
                break;
            case R.id.Answer_A_Release:
                intent =new Intent();
                intent.setClass(creatQuestion.this,Saoku.class);
                startActivityForResult(intent,051);
                break;
            case R.id.Answer_B_Release:
                intent =new Intent();
                intent.setClass(creatQuestion.this,Saoku.class);
                startActivityForResult(intent,052);
                break;
            case R.id.Answer_C_Release:
                intent =new Intent();
                intent.setClass(creatQuestion.this,Saoku.class);
                startActivityForResult(intent,053);
                break;
            case R.id.Answer_D_Release:
                intent =new Intent();
                intent.setClass(creatQuestion.this,Saoku.class);
                startActivityForResult(intent,054);
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        //問題添加騷庫
        if(requestCode==050&&resultCode==1&&data!=null){
            Bundle bundle = data.getExtras();
            String a=bundle.getString("SaokuText");
            String img=bundle.getString("SaokuImg");
            String video=bundle.getString("SaokuVideo");
            String Gif=bundle.getString("SaokuGif");
            log.e("gif",Gif);
            if(a!=null) {
                editTextsubject.setText(a);
                Subject = a;
                log.e("Subject",Subject);
            }else if(img!=null){
                SaokuResource=img.substring(28);
                Picasso.with(creatQuestion.this).load(img).into(imageView);
            }else if(video!=null){
                log.e("video",video);
                LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.saoku_video_item, null);
                replaceVieo(video,layout);
                LinearLayout linearLayout = (LinearLayout) findViewById(R.id.CreatQuestion_Dynamic);
                linearLayout.removeView(findViewById(R.id.creatQuestion_image));
                linearLayout.addView(layout);
                SaokuResource=video.substring(28);
                log.e("SaokuResource",SaokuResource);
            } else if(Gif!=null){
                log.e("gifQUESTION",Gif);
                LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.gif_item, null);
                GifImageView gifImageView=(GifImageView) layout.findViewById(R.id.info_gif1_A);

                File saveImgPath = getImageDir(this);
                File gifSavePath1 = new File(saveImgPath, "gif1");
                displayImage(Gif, gifSavePath1, gifImageView);

                LinearLayout linearLayout = (LinearLayout) findViewById(R.id.CreatQuestion_Dynamic);
                linearLayout.removeView(findViewById(R.id.creatQuestion_image));
                linearLayout.addView(layout);

                SaokuResource=Gif.substring(28);
                log.e("SaokuResource",SaokuResource);
            }
        }
        //答案A添加騷庫
        if(requestCode==051&&resultCode==1&&data!=null){
            Bundle bundle = data.getExtras();
            String a=bundle.getString("SaokuText");
            String b=bundle.getString("SaokuImg");
            String video=bundle.getString("SaokuVideo");
            String Gif=bundle.getString("SaokuGif");
            log.e("gifAnswerA",Gif);
            if(a!=null){
                editTextAnswerA.setText(a);
                answerA=a;
            }else if(b!=null){
                String path=b.substring(28);
                SaokuResourceA=path;
                Picasso.with(creatQuestion.this).load(b).into(imageViewA);
            }else if(video!=null){
                log.e("video",video);
                LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.saoku_video_item, null);
                replaceVieo(video,layout);
                LinearLayout linearLayout = (LinearLayout) findViewById(R.id.CreatQuestion_Answer_A_Dynamic);
                linearLayout.removeView(findViewById(R.id.creatQuestion_AnswerA_Image));
                linearLayout.addView(layout);
                SaokuResourceA=video.substring(28);

            }else if(Gif!=null){

                LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.gif_item, null);
                GifImageView gifImageView=(GifImageView) layout.findViewById(R.id.info_gif1_A);
                File saveImgPath = getImageDir(this);
                File gifSavePath1 = new File(saveImgPath, "gif1");
                displayImage(Gif, gifSavePath1, gifImageView);

                LinearLayout linearLayout = (LinearLayout) findViewById(R.id.CreatQuestion_Answer_A_Dynamic);
                linearLayout.removeView(findViewById(R.id.creatQuestion_AnswerA_Image));
                linearLayout.addView(layout);

                SaokuResourceA=Gif.substring(28);
                log.e("SaokuResource",SaokuResource);
            }
        }
        //答案B添加騷庫
        if(requestCode==052&&resultCode==1&&data!=null){
            Bundle bundle = data.getExtras();
            String a=bundle.getString("SaokuText");
            String b=bundle.getString("SaokuImg");
            String video=bundle.getString("SaokuVideo");
            String Gif=bundle.getString("SaokuGif");
            log.e("gifAnswerb",Gif);
            if(a!=null){
                editTextAnswerB.setText(a);
                answerB=a;
            }else if(b!=null){
                String path=b.substring(28);
                SaokuResourceB=path;
                Picasso.with(creatQuestion.this).load(b).into(imageViewB);
            }else if(video!=null){
                log.e("video",video);
                LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.saoku_video_item, null);
                replaceVieo(video,layout);
                LinearLayout linearLayout = (LinearLayout) findViewById(R.id.CreatQuestion_Answer_B_Dynamic);
                linearLayout.removeView(findViewById(R.id.creatQuestion_AnswerB_Image));
                linearLayout.addView(layout);
                SaokuResourceB=video.substring(28);

            }else if(Gif!=null){
                log.e("gif",Gif);
                LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.gif_item, null);
                GifImageView gifImageView=(GifImageView) layout.findViewById(R.id.info_gif1_A);
                File saveImgPath = getImageDir(this);
                File gifSavePath1 = new File(saveImgPath, "gif1");
                displayImage(Gif, gifSavePath1, gifImageView);

                LinearLayout linearLayout = (LinearLayout) findViewById(R.id.CreatQuestion_Answer_B_Dynamic);
                linearLayout.removeView(findViewById(R.id.creatQuestion_AnswerB_Image));
                linearLayout.addView(layout);

                SaokuResourceB=Gif.substring(28);
                log.e("SaokuResource",SaokuResource);
            }
        }
        //答案C添加騷庫
        if(requestCode==053&&resultCode==1&&data!=null){
            Bundle bundle = data.getExtras();
            String a=bundle.getString("SaokuText");
            String b=bundle.getString("SaokuImg");
            String video=bundle.getString("SaokuVideo");
            String Gif=bundle.getString("SaokuGif");
            log.e("gifAnswerC",Gif);
            if(a!=null){
                editTextAnswerC.setText(a);
                answerC=a;
            }else if(b!=null){
                String path=b.substring(28);
                SaokuResourceC=path;
                log.e("SaokuResource",SaokuResourceC);
                Picasso.with(creatQuestion.this).load(b).into(imageViewC);
            }else if(video!=null){
                log.e("video",video);
                LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.saoku_video_item, null);
                replaceVieo(video,layout);
                LinearLayout linearLayout = (LinearLayout) findViewById(R.id.CreatQuestion_Answer_B_Dynamic);
                linearLayout.removeView(findViewById(R.id.creatQuestion_AnswerB_Image));
                linearLayout.addView(layout);
                SaokuResourceC=video.substring(28);

            }else if(Gif!=null){
                log.e("gif",Gif);
                LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.gif_item, null);
                GifImageView gifImageView=(GifImageView) layout.findViewById(R.id.info_gif1_A);
                File saveImgPath = getImageDir(this);
                File gifSavePath1 = new File(saveImgPath, "gif1");
                displayImage(Gif, gifSavePath1, gifImageView);

                LinearLayout linearLayout = (LinearLayout) findViewById(R.id.CreatQuestion_Answer_C_Dynamic);
                linearLayout.removeView(findViewById(R.id.creatQuestion_AnswerC_Image));
                linearLayout.addView(layout);

                SaokuResourceC=Gif.substring(28);
                log.e("SaokuResource",SaokuResource);
            }
        }
        //答案D添加騷庫
        if(requestCode==054&&resultCode==1&&data!=null){
            Bundle bundle = data.getExtras();
            String a=bundle.getString("SaokuText");
            String b=bundle.getString("SaokuImg");
            String video=bundle.getString("SaokuVideo");
            String Gif=bundle.getString("SaokuGif");
            log.e("giAnswerD",Gif);
            if(a!=null){
                editTextAnswerD.setText(a);
                answerD=a;
            }else if(b!=null){
                String path=b.substring(28);
                SaokuResourceD=path;
                log.e("SaokuResource",SaokuResourceD);
                Picasso.with(creatQuestion.this).load(b).into(imageViewD);
            }else if(video!=null){
                log.e("video",video);
                LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.saoku_video_item, null);
                replaceVieo(video,layout);
                LinearLayout linearLayout = (LinearLayout) findViewById(R.id.CreatQuestion_Answer_D_Dynamic);
                linearLayout.removeView(findViewById(R.id.creatQuestion_AnswerD_Image));
                linearLayout.addView(layout);
                SaokuResourceD=video.substring(28);

            }else if(Gif!=null){
                log.e("gif",Gif);
                LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.gif_item, null);
                GifImageView gifImageView=(GifImageView) layout.findViewById(R.id.info_gif1_A);
                File saveImgPath = getImageDir(this);
                File gifSavePath1 = new File(saveImgPath, "gif1");
                displayImage(Gif, gifSavePath1, gifImageView);

                LinearLayout linearLayout = (LinearLayout) findViewById(R.id.CreatQuestion_Answer_D_Dynamic);
                linearLayout.removeView(findViewById(R.id.creatQuestion_AnswerD_Image));
                linearLayout.addView(layout);

                SaokuResourceD=Gif.substring(28);
                log.e("SaokuResource",SaokuResource);
            }
        }
        //创建骚问，添加图片和视频按钮回调事件
        if (requestCode == 1 && resultCode == Activity.RESULT_OK && data != null) {
            uri = data.getData();//解决方案
            String path=uri.toString();
            log.e("path",path);
            if (path.endsWith(".jpg")||path.endsWith(".png")) {
                uri = geturi(data);//解决方案
                QuestionPath = path(uri);
                log.e("QuestionPath",QuestionPath);
                bitmapQuestion=getSmallBitmap(path(uri));
                imageView.setImageBitmap(bitmapQuestion);

            }else if(path.endsWith(".mp4")){//如果返回的视频文件，布局进行切换
                QuestionPath=getPhotoPathFromContentUri(this,uri);
                LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.saoku_video_item, null);
                replaceVieo(QuestionPath,layout);
                LinearLayout linearLayout = (LinearLayout) findViewById(R.id.CreatQuestion_Dynamic);
                linearLayout.removeView(findViewById(R.id.creatQuestion_image));
                linearLayout.addView(layout);
            }

        }
        if (requestCode == 2 && resultCode == Activity.RESULT_OK && data != null) {
            uriA = geturi(data);//解决方案
            imagePathA=path(uriA);
            imageViewA.setImageBitmap(getSmallBitmap(path(uriA)));
        }
        if (requestCode == 3 && resultCode == Activity.RESULT_OK && data != null) {
            uriB = geturi(data);//解决方案
            imagePathB=path(uriB);
            imageViewB.setImageBitmap(getSmallBitmap(path(uriB)));
        }
        if (requestCode == 4 && resultCode == Activity.RESULT_OK && data != null) {
            uriC = geturi(data);//解决方案
            imagePathC=path(uriC);
            imageViewC.setImageBitmap(getSmallBitmap(path(uriC)));
        }
        if (requestCode == 5 && resultCode == Activity.RESULT_OK && data != null) {
            uriD = geturi(data);//解决方案
            imagePathD=path(uriD);
            imageViewD.setImageBitmap(getSmallBitmap(path(uriD)));
            log.e("imagePathD",imagePathD);
        }
        //惡搞答案A回調接口
        if (requestCode == 001 && resultCode == 002 && data != null) {
            Bundle bundle = data.getExtras();
             contentA=bundle.getString("spoof_content");
            SpoofImaA=bundle.getString("spoof_imgpath");
            if(contentA.isEmpty()&&SpoofImaA.isEmpty()) {
                spoof_typeA = 0;
            }else if(contentA!=null&&SpoofImaA.isEmpty()){
                spoof_typeA=1;
            }else if(SpoofImaA.endsWith(".jpg")||SpoofImaA.endsWith(".png")){
                spoof_typeA=2;
            }else if(SpoofImaA.endsWith(".mp3")){
                spoof_typeA=3;
            }else if(SpoofImaA.endsWith(".mp4")){
                spoof_typeA=4;
            }
            fileSpoofFileA=new File(SpoofImaA);
        }

        //惡搞答案B回調接口
        if (requestCode == 002 && resultCode == 002 && data != null) {
            Bundle bundle = data.getExtras();
             contentB=bundle.getString("spoof_content");
            SpoofImaB=bundle.getString("spoof_imgpath");
            if(contentB.isEmpty()&&SpoofImaB.isEmpty()) {
                spoof_typeB = 0;
            }else if(contentB!=null&&SpoofImaB.isEmpty()){
                spoof_typeB=1;
            }else if(SpoofImaB.endsWith(".jpg")||SpoofImaB.endsWith(".png")){
                spoof_typeB=2;
            }else if(SpoofImaB.endsWith(".mp3")){
                spoof_typeB=3;
            }else if(SpoofImaB.endsWith(".mp4")){
                spoof_typeB=4;
            }
            fileSpoofFileB=new File(SpoofImaB);
        }
        //惡搞答案C回調接口
        if (requestCode == 003 && resultCode == 002 && data != null) {
            Bundle bundle = data.getExtras();
             contentC=bundle.getString("spoof_content");
            SpoofImaC=bundle.getString("spoof_imgpath");
            if(contentC.isEmpty()&&SpoofImaC.isEmpty()) {
                spoof_typeC = 0;
            }else if(contentC!=null&&SpoofImaC.isEmpty()){
                spoof_typeC=1;
            }else if(SpoofImaC.endsWith(".jpg")||SpoofImaC.endsWith(".png")){
                spoof_typeC=2;
            }else if(SpoofImaC.endsWith(".mp3")){
                spoof_typeC=3;
            }else if(SpoofImaC.endsWith(".mp4")){
                spoof_typeC=4;
            }
            fileSpoofFileC=new File(SpoofImaC);

        }
        //惡搞答案D回調接口
        if (requestCode == 004 && resultCode == 002 && data != null) {
            Bundle bundle = data.getExtras();
             contentD=bundle.getString("spoof_content");
            SpoofImaD=bundle.getString("spoof_imgpath");
            if(contentD.isEmpty()&&SpoofImaD.isEmpty()) {
                spoof_typeD = 0;
            }else if(contentD!=null&&SpoofImaD.isEmpty()){
                spoof_typeD=1;
            }else if(SpoofImaD.endsWith(".jpg")||SpoofImaD.endsWith(".png")){
                spoof_typeD=2;
            }else if(SpoofImaD.endsWith(".mp3")){
                spoof_typeD=3;
            }else if(SpoofImaD.endsWith(".mp4")){
                spoof_typeD=4;
            }
            fileSpoofFileD=new File(SpoofImaD);
        }

        if(requestCode==010&&resultCode==011&&data!=null){
            Bundle bundle = data.getExtras();
            QuestionPath=bundle.getString("Voice_Path");
            log.e("QuestionVoice",QuestionPath);
            //如果问题是MP3，布局就替换成语音播放界面
                if (QuestionPath.endsWith(".mp3")) {
                    LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.dynamic_voice_a, null);
                    LinearLayout linearLayout = (LinearLayout) findViewById(R.id.CreatQuestion_Dynamic);
                    linearLayout.removeView(findViewById(R.id.creatQuestion_image));
                    linearLayout.addView(layout);
                    ImageButton QuestionPlay=(ImageButton)layout.findViewById(R.id.Dymanic_play_voice_A);
                    mediaPlayer=new MediaPlayer();
                    try {
                        mediaPlayer.setDataSource(QuestionPath);
                        mediaPlayer.prepare();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    QuestionPlay.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            mediaPlayer.start();
                        }
                    });
            }
        }
        if(requestCode==021&&resultCode==011&&data!=null){
            log.e("VoiceStr","VoiceStr");
            Bundle bundle = data.getExtras();
            imagePathA=bundle.getString("Voice_Path");
            log.e("QuestionVoiceA",imagePathA);
            //如果问题是MP3，布局就替换成语音播放界面
            if (imagePathA.endsWith(".mp3")) {
                LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.dynamic_voice_a, null);
                LinearLayout linearLayout = (LinearLayout) findViewById(R.id.CreatQuestion_Answer_A_Dynamic);
                linearLayout.removeView(findViewById(R.id.CreatQuestion_Answer_A_Dynamic));
                linearLayout.addView(layout);
                ImageButton QuestionPlayA=(ImageButton)findViewById(R.id.Dymanic_play_voice_A);
                mediaPlayer=new MediaPlayer();
                try {
                    mediaPlayer.setDataSource(imagePathA);
                    mediaPlayer.prepare();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                QuestionPlayA.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mediaPlayer.start();
                    }
                });
            }
        }
        //
        if(requestCode==022&&resultCode==011&&data!=null){
            Bundle bundle = data.getExtras();
            imagePathB=bundle.getString("Voice_Path");


            //如果问题是MP3，布局就替换成语音播放界面
            if (imagePathB.endsWith(".mp3")) {
                LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.dynamic_voice_b, null);
                LinearLayout linearLayout = (LinearLayout) findViewById(R.id.CreatQuestion_Answer_B_Dynamic);
                linearLayout.removeView(findViewById(R.id.creatQuestion_AnswerB_Image));
                linearLayout.addView(layout);
                ImageButton QuestionPlayB=(ImageButton)findViewById(R.id.Dymanic_play_voice_B);
                QuestionPlayB.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mediaPlayer=new MediaPlayer();
                        try {
                            mediaPlayer.setDataSource(imagePathB);
                            mediaPlayer.prepare();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                        mediaPlayer.start();
                    }
                });
            }
        }
        if(requestCode==023&&resultCode==011&&data!=null){
            Bundle bundle = data.getExtras();
            imagePathC=bundle.getString("Voice_Path");
            //如果问题是MP3，布局就替换成语音播放界面
            if (imagePathC.endsWith(".mp3")) {
                LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.dynamic_voice_c, null);
                LinearLayout linearLayout = (LinearLayout) findViewById(R.id.CreatQuestion_Answer_C_Dynamic);
                linearLayout.removeView(findViewById(R.id.creatQuestion_AnswerC_Image));
                linearLayout.addView(layout);
                ImageButton QuestionPlayB=(ImageButton)findViewById(R.id.Dymanic_play_voice_C);
                mediaPlayer=new MediaPlayer();
                try {
                    mediaPlayer.setDataSource(imagePathC);
                    mediaPlayer.prepare();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                QuestionPlayB.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mediaPlayer.start();
                    }
                });
            }
        }
        if(requestCode==024&&resultCode==011&&data!=null){
            Bundle bundle = data.getExtras();
            imagePathD=bundle.getString("Voice_Path");
            //如果问题是MP3，布局就替换成语音播放界面
            if (imagePathD.endsWith(".mp3")) {
                LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.dynamic_voice_d, null);
                LinearLayout linearLayout = (LinearLayout) findViewById(R.id.CreatQuestion_Answer_D_Dynamic);
                linearLayout.removeView(findViewById(R.id.creatQuestion_AnswerD_Image));
                linearLayout.addView(layout);
                ImageButton QuestionPlayB=(ImageButton)findViewById(R.id.Dymanic_play_voice_D);
                mediaPlayer=new MediaPlayer();
                try {
                    mediaPlayer.setDataSource(imagePathD);
                    mediaPlayer.prepare();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                QuestionPlayB.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mediaPlayer.start();
                    }
                });
            }
        }
        if (requestCode == 030 && resultCode == Activity.RESULT_OK && data != null) {
            Uri uri=data.getData();
            imagePathA=getPhotoPathFromContentUri(this,uri);
            LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.saoku_video_item, null);
            replaceVieo(imagePathA,layout);
            LinearLayout linearLayout = (LinearLayout) findViewById(R.id.CreatQuestion_Answer_A_Dynamic);
            linearLayout.removeView(findViewById(R.id.creatQuestion_AnswerA_Image));
            linearLayout.addView(layout);


        }
        if (requestCode == 031 && resultCode == Activity.RESULT_OK && data != null) {
            Uri uri=data.getData();
            imagePathB=getPhotoPathFromContentUri(this,uri);
            LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.saoku_video_item, null);
            replaceVieo(imagePathB,layout);
            LinearLayout linearLayout = (LinearLayout) findViewById(R.id.CreatQuestion_Answer_B_Dynamic);
            linearLayout.removeView(findViewById(R.id.creatQuestion_AnswerB_Image));
            linearLayout.addView(layout);
        }
        if (requestCode == 032 && resultCode == Activity.RESULT_OK && data != null) {
            Uri uri=data.getData();
            imagePathC=getPhotoPathFromContentUri(this,uri);
            LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.saoku_video_item, null);
            replaceVieo(imagePathC,layout);
            LinearLayout linearLayout = (LinearLayout) findViewById(R.id.CreatQuestion_Answer_C_Dynamic);
            linearLayout.removeView(findViewById(R.id.creatQuestion_AnswerC_Image));
            linearLayout.addView(layout);
        }
        if (requestCode == 033 && resultCode == Activity.RESULT_OK && data != null) {
            Uri uri=data.getData();
            imagePathD=getPhotoPathFromContentUri(this,uri);
            LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.saoku_video_item, null);
            replaceVieo(imagePathD,layout);
            LinearLayout linearLayout = (LinearLayout) findViewById(R.id.CreatQuestion_Answer_D_Dynamic);
            linearLayout.removeView(findViewById(R.id.creatQuestion_AnswerD_Image));
            linearLayout.addView(layout);
        }
        if(requestCode==040&&resultCode==004&&data!=null){
            Bundle bundle = data.getExtras();
            textSpecialA=bundle.getString("special");
            log.e("textSpecial",textSpecialA+"");
        }
        if(requestCode==041&&resultCode==004&&data!=null){
            Bundle bundle = data.getExtras();
            textSpecialB=bundle.getString("special");
            log.e("textSpecial",textSpecialB+"");
        }
        if(requestCode==042&&resultCode==004&&data!=null){
            Bundle bundle = data.getExtras();
            textSpecialC=bundle.getString("special");
            log.e("textSpecial",textSpecialC+"");
        }
        if(requestCode==043&&resultCode==004&&data!=null){
            Bundle bundle = data.getExtras();
            textSpecialD=bundle.getString("special");
            log.e("textSpecial",textSpecialD+"");
        }


        super.onActivityResult(requestCode, resultCode, data);
    }

    public Uri geturi(Intent intent) {
        Uri uri = intent.getData();
        String type = intent.getType();
        if (uri.getScheme().equals("file") && (type.contains("image/"))) {
            String path = uri.getEncodedPath();
            if (path != null) {
                path = Uri.decode(path);
                ContentResolver cr = this.getContentResolver();
                StringBuffer buff = new StringBuffer();
                buff.append("(").append(MediaStore.Images.ImageColumns.DATA).append("=")
                        .append("'" + path + "'").append(")");
                Cursor cur = cr.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                        new String[] { MediaStore.Images.ImageColumns._ID },
                        buff.toString(), null, null);
                int index = 0;
                for (cur.moveToFirst(); !cur.isAfterLast(); cur.moveToNext()) {
                    index = cur.getColumnIndex(MediaStore.Images.ImageColumns._ID);
                    // set _id value
                    index = cur.getInt(index);
                }
                if (index == 0) {
                    // do nothing
                } else {
                    Uri uri_temp = Uri
                            .parse("content://media/external/images/media/" + index);
                    if (uri_temp != null) {
                        uri = uri_temp;
                    }
                }
            }
        }


        return uri;
    }
    private String path(Uri uri ) {

        String path = null;
        String[] proj = {MediaStore.Images.Media.DATA};
        Cursor cursor = managedQuery(uri, proj, null, null, null);
        if (cursor != null) {
            ContentResolver cr = this.getContentResolver();
            int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            cursor.moveToFirst();
            path = cursor.getString(column_index);// 图片在的路径
        }
        return path;

    }

    @Override
    public void onError() {

    }

    @Override
    public void onExpend() {

    }

    @Override
    public void onShrik() {

    }

    //EditText的监听器
    private class TextChange implements TextWatcher{

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            Subject=editTextsubject.getText().toString();
            answerA=editTextAnswerA.getText().toString();
            answerB=editTextAnswerB.getText().toString();
            answerC=editTextAnswerC.getText().toString();
            answerD=editTextAnswerD.getText().toString();
            preferences = getSharedPreferences("UserContent", MODE_PRIVATE);
            editor = preferences.edit();
            editor.putString("Content",Subject);
            editor.putString("ContentA",answerA);
            editor.putString("ContentB",answerB);
            editor.putString("ContentC",answerC);
            editor.putString("ContentD",answerD);
            editor.commit();
        }
    }
    public void setPlayView(VideoPlayView playView) {
        playView.setMediaPlayerListenr(this);
    }
    private void replaceVieo(final String path,LinearLayout layout){
        ImageView play=(ImageView)layout.findViewById(R.id.saoku_play_btn);
        final VideoPlayView playView=(VideoPlayView)layout.findViewById(R.id.saoku_video_play_view);
        final FrameLayout showLayout=(FrameLayout)layout.findViewById(R.id.saoku_show_layout);
        play.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                isPlaying = true;
                showLayout.setVisibility(View.GONE);
                playView.setUrl(path);
                setPlayView(playView);
                playView.openVideo();
                playView.setVisibility(View.VISIBLE);
            }
        });
    }
    public void displayImage(String url, File saveFile, final GifImageView gifView){
        HttpUtils http = new HttpUtils();
        // 下载图片
        http.download(url, saveFile.getAbsolutePath(), new RequestCallBack<File>() {
            public void onSuccess(ResponseInfo<File> responseInfo) {
                try {
                    Log.e("tag", "onSuccess========" + responseInfo.result.getAbsolutePath());
                    GifDrawable gifFrom = new GifDrawable( responseInfo.result.getAbsolutePath() );
                    gifView.setImageDrawable(gifFrom);
                }
                catch(Exception e){
                    Log.e("tag", e.getMessage());
                }
            }

            @Override
            public void onFailure(com.lidroid.xutils.exception.HttpException e, String s) {
                Log.e("tag", "onFailure========" + s);
            }});
    }
    public File getImageDir(Context context){
        File file = getFilesDir(context, "images");
        return file;
    }
    public File getFilesDir(Context context, String tag){
        if(isSdCardExist() == true){
            return context.getExternalFilesDir(tag);
        }
        else{
            return context.getFilesDir();
        }
    }
    public boolean isSdCardExist() {
        if (Environment.getExternalStorageState().equals(
                Environment.MEDIA_MOUNTED)) {
            return true;
        }
        return false;
    }

}
